function [] = estimation_consumerAdoptions(runId);

%%% Add paths
addpath('../model_funcs');
addpath('../model_funcs/dim_specific_funcs/dim3');
addpath('../general_funcs');

%%%%% Read config to get runFolder
config = getConfig_consumerAdoptions(runId);
modelId = config.modelId;
runFolder = config.runFolder;

%%% Get input/output files
runDataFile = sprintf('%s/runData.mat', runFolder);
outputMatFile = sprintf('%s/results.mat', runFolder);
outputCSVFile = sprintf('%s/results.csv', runFolder);

%%% Load data
load(runDataFile);
NumParams = data.dims.NumParams;
paramNames = get_param_names_consumerAdoptions(data);

%%% Define starting point params0
if isfield(config, 'startingPointFile')
	disp(sprintf('Loading starting point from file %s...', config.startingPointFile));
	load(config.startingPointFile, 'params_hat');
	params0 = params_hat;
	clear params_hat;
else
	disp('Using starting point at zero (except for intercept)...');
	NumParams = data.dims.NumParams;
	intercept_idx = find(strcmp(paramNames, 'Beta ttIntercept on NewConsumers'));
	params0 = zeros(NumParams, 1);
	params0(intercept_idx) = -12;
end

%%% Display initial params
disp('========== INITIAL PARAMETER VALUES ==========');
myTable = array2table(params0);
myTable.Properties.RowNames = paramNames; myTable.Properties.VariableNames = {'StartingValue'};
disp(myTable);

%%% Launch estimation
data.LL_offset = 0; % Approximation to continuous-time mode --> no need for y! in denominator

% Estimation in one shot
if config.modelId ~= 3
	data.logLambdaOffset = data.logLambdaOffset_dim1 + data.logLambdaOffset_dim2; % T x K1 x K2
	data.logLambdaOffset = reshape(data.logLambdaOffset, [prod(size(data.logLambdaOffset)) 1]); % (T*K1*K2) x 1
	[params_hat, covMat, params_ses, modelFits] = estimate_model(modelId, data, params0);
else
	% Estimation by blocks
	[params_hat, covMat, params_ses, modelFits] = estimate_model_by_blocks(modelId, data, 100, params0);
end

%%% Display results
disp('========== ESTIMATES ==========');
myTable = reportSubmodelResults(paramNames, params_hat, params_ses, modelFits);
disp(myTable);

%%% Output results to files
save(outputMatFile, 'params_hat', 'params_ses', 'covMat', 'myTable', 'modelFits', '-v7.3');

% Keep 2 decimal points and write to CSV
myTable = formatTableValues(myTable);
writetable(myTable, outputCSVFile,'WriteRowNames',true);

end
